<?php

namespace AdminBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class cronTaskCommand extends ContainerAwareCommand
{

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('cron:task:run')
            ->setDescription('Execute cron task ');
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
//        $scheduler = Scheduler::create($this->getContainer());
        $output->writeln('scheduler create ok.');
        $scheduler = $this->getContainer()->get('cron.task.scheduler');
        $scheduler->publish();

        $jobs = $scheduler->start();
        $output->writeln('scheduler start [' . $jobs . '] jobs.');

        $tasks = $scheduler->run();

        $scheduler->publish();

        $scheduler->nextScheduler();

        $output->writeln('scheduler [' . $tasks . '] tasks finished.');
    }
}
